<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\AppUpdateInfo
 *
 * @property int $id
 * @property string $update_time app更新时间
 * @property string $title 窗口标题
 * @property string $version 版本号
 * @property string $install_pkg_url 安装包链接
 * @property string $update_text 更新文本
 * @property int $status 更新版本状态
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo whereInstallPkgUrl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo whereUpdateText($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo whereUpdateTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo whereVersion($value)
 * @mixin \Eloquent
 * @property string $app_update_time app更新时间
 * @property string $app_update_text 更新文本
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo whereAppUpdateText($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo whereAppUpdateTime($value)
 * @property-read mixed $status_str
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo byStatus($status)
 * @property string $ios_pkg_url ios安装包url
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AppUpdateInfo whereIosPkgUrl($value)
 */
class AppUpdateInfo extends Model
{
    /*
     * 状态： 1=生效中 2=已失效
     * */
    const STATUS_USE = 1,STATUS_NOT_USE = 2;

    /*
     * 是否强制更新 1=是 2=否
     */
    const UPDATE_YES = 1,UPDATE_NO = 2;

    static $STATUS = [
        self::STATUS_USE => '生效中',
        self::STATUS_NOT_USE => '已失效'
    ];

    protected $fillable = ['app_update_time','title','version','install_pkg_url','app_update_text','status','ios_pkg_url','is_force'];

    protected $dates = [
        'app_update_time'
    ];

    protected $appends = [
        'status_str'
    ];

    /**
     * 状态查询作用域
     * @param $query
     * @param $status
     * @return mixed
     * @author luwei
     * @date 2019-01-11 14:35
     */
    public function scopeByStatus($query, $status){
        return $query->where('status',$status);
    }
    //
    public function getStatusStrAttribute(){
        if($this->attributes['status']){
            return AppUpdateInfo::$STATUS[$this->attributes['status']];
        }
        return '';
    }
}
